<?php
/************************FoxPHP威客系统************************/
/*                                                            */
/*  FoxPHP.Com (C)2006-2016 FoxPHP Inc.                       */
/*  This is NOT a freeware, use is subject to license terms   */
/*  FoxPHP威客系统是商业软件,使用于商业用途请购买授权         */
/*  V3.0 2016.3                                               */
/*  foxphp@aliyun.com                                         */
/*  http://www.foxphp.com                                     */
/*                                                            */
/**************************************************************/

//发布任务类
namespace Post\Controller;
$_POST['datatype']='json';
class TaskController extends \Member\Controller\IndexController {
	
	//第一步 发布插入数据
	public function publishinsertAction(){
		
		if(intval($_GET['mobile'])){
			//移动
		}else{
			if(IsPost('Submit')){
				//模块
				
				$model=new \Data\Model\DataModel();
				$id=$model->InsertTask($model->FormatData('task'));
				if($id>0){
					$this->ajaxReturn(array('title'=>'填写需求信息','message'=>'填写需求信息成功!','status'=>'ok','refresh'=>true,'url'=>'/task/publish/setmoney/id/'.$id));
				}else{
					$this->ajaxReturn(array('title'=>'验证失败','message'=>$model->getError(),'status'=>'error'));
				}
			}else{
				$this->ajaxReturn(array('title'=>'验证失败','message'=>'没有数据提交！'.$result,'status'=>'error'));
			}
		}
	}
	
	//第一步 发布修改数据
	public function publisheditAction(){
		
		if(intval($_GET['mobile'])){
			//移动
		}else{
			if(IsPost('Submit')){
				//print_r($_POST);
				//模块
				
				$model=new \Data\Model\DataModel();
				
				if(!$model->IsData($_POST['id'])){
					$this->ajaxReturn(array('title'=>'验证失败','message'=>'没有数据提交！'.$result,'status'=>'error'));
				}
				
				$id=$model->EditTask($model->FormatData('task'));
				if($id>0){
					$this->ajaxReturn(array('title'=>'填写需求信息','message'=>'填写需求信息成功!','status'=>'ok','refresh'=>true,'url'=>'/task/publish/setmoney/id/'.$id));
				}else{
					$this->ajaxReturn(array('title'=>'验证失败','message'=>$model->getError(),'status'=>'error'));
				}
			}else{
				$this->ajaxReturn(array('title'=>'验证失败','message'=>'没有数据提交！'.$result,'status'=>'error'));
			}
		}
	}
	
	
	
	//第二步
	public function publishmoneyAction(){
		
		if(intval($_GET['mobile'])){
			//移动
		}else{
			if(IsPost('Submit')){
				
				//模块
				$model=new \Data\Model\DataModel();
				
				if(!$model->IsData($_POST['id'])){
					$this->ajaxReturn(array('title'=>'验证失败','message'=>'没有数据提交！'.$result,'status'=>'error'));
				}
				
				$id=$model->EditTask($model->FormatTaskPublishMoney(),0);
				if($id>0){
					$this->ajaxReturn(array('title'=>'设置赏金','message'=>'设置赏金成功!','status'=>'ok','refresh'=>true,'url'=>'/task/publish/confirm/id/'.$id));
				}else{
					$this->ajaxReturn(array('title'=>'验证失败','message'=>$model->getError(),'status'=>'error'));
				}
		
			}else{
				$this->ajaxReturn(array('title'=>'验证失败','message'=>'没有数据提交！'.$result,'status'=>'error'));
			}
		}
	}
	
	//第三步
	public function confirmAction(){
		
		if(intval($_GET['mobile'])){
			//移动
		}else{
			if(IsPost('Submit')){
				
				//模块
				$model=new \Data\Model\DataModel();
				
				if(!$model->IsData($_POST['id'])){
					$this->ajaxReturn(array('title'=>'验证失败','message'=>'没有数据提交！'.$result,'status'=>'error'));
				}
				
				$id=$model->PayTask();
				if($id>0){
					$this->ajaxReturn(array('title'=>'确认发布','message'=>'发布成功!','status'=>'ok','refresh'=>true,'url'=>'/task/'.$id));
				}else{
					$this->ajaxReturn(array('title'=>'发布失败','message'=>$model->getError(),'status'=>'error'));
				}
		
			}else{
				$this->ajaxReturn(array('title'=>'验证失败','message'=>'没有数据提交！'.$result,'status'=>'error'));
			}
		}
	}
	
	//提交稿件
	public function postdraftAction(){
		
		if(intval($_GET['mobile'])){
			//移动
		}else{
			if(IsPost('Submit')){
				
				//模块
				$model=new \Data\Model\DataModel();
				
				if(!$model->IsData($_POST['id'])){
					$this->ajaxReturn(array('title'=>'验证失败','message'=>'没有数据提交！'.$result,'status'=>'error'));
				}
				
				$data=$model->PostDraft();
				if($data['oid']>0){
					$this->ajaxReturn(array('title'=>'确认发布','message'=>'发布成功!','status'=>'ok','refresh'=>true,'url'=>'/task/'.intval($_POST['id'])));
				}else{
					$this->ajaxReturn(array('title'=>'发布失败','message'=>$model->getError(),'status'=>'error'));
				}
		
			}else{
				$this->ajaxReturn(array('title'=>'验证失败','message'=>'没有数据提交！！'.$result,'status'=>'error'));
			}
		}
	}
	
	//稿件列表
	public function listdraftAction(){
		
		if(intval($_GET['mobile'])){
			//移动
		}else{
			//模块
			
			$model=new \Data\Model\DataModel();
			$task=$model->GetData($_GET['id']);
			if(empty($task['id'])){
				$this->ajaxReturn(array('title'=>'验证失败','message'=>'没有数据提交！'.$result,'status'=>'error'));
			}
			
			$model=new \Data\Model\DataOrderModel();
			$data=$model->ListDraft($task);
			if(!empty($data['list'])){
				$this->ajaxReturn(array('title'=>'确认发布','message'=>'发布成功!','status'=>'ok','refresh'=>true,'data'=>$data));
			}else{
				$this->ajaxReturn(array('title'=>'发布失败','message'=>$model->getError(),'status'=>'error'));
			}
		}
	}
	
	//稿件评论
	function postcommentAction(){
		if(intval($_GET['mobile'])){
			//移动
		}else{
			if(IsPost('Submit')){	
				
				//模块
				$model=new \Data\Model\DataModel();
				$task=$model->GetData($_GET['id']);
				if(empty($task['id'])){
					$this->ajaxReturn(array('title'=>'验证失败','message'=>'没有数据提交！'.$result,'status'=>'error'));
				}
				
				$model=new \Data\Model\DataModel();
				$data=$model->PostComment($task);
				if(!empty($data)){
					$this->ajaxReturn(array('title'=>'发布评论','message'=>'发布成功!','status'=>'ok','refresh'=>false,'data'=>$data));
				}else{
					$this->ajaxReturn(array('title'=>'发布失败','message'=>$model->getError(),'status'=>'error'));
				}
				
			}else{
				$this->ajaxReturn(array('title'=>'验证失败','message'=>'没有数据提交！！'.$result,'status'=>'error'));
			}
		}
	}
	
	//稿件中标
	function successAction(){
		if(intval($_GET['mobile'])){
			//移动
		}else{
			//模块
			
			$model=new \Data\Model\DataModel();
			$task=$model->GetData($_GET['id']);
			if(empty($task['id'])){
				$this->ajaxReturn(array('title'=>'验证失败','message'=>'没有数据提交！'.$result,'status'=>'error'));
			}
			
			$model=new \Data\Model\DataModel();
			$id=$model->SuccessDraft($task);
			if(!empty($id)){
				$callback=$this->GetCallback();
				$this->ajaxReturn(array('title'=>'稿件操作','message'=>'操作成功!','status'=>'ok','refresh'=>false,'callback'=>"GetListDraft('".$callback[0]."','".$callback[1]."')"));
			}else{
				$this->ajaxReturn(array('title'=>'稿件操作','message'=>$model->getError(),'status'=>'error'));
			}
		}
	}
	
	//稿件不合格
	function failureAction(){
		if(intval($_GET['mobile'])){
			//移动
		}else{
			//模块
			
			$model=new \Data\Model\DataModel();
			$task=$model->GetData($_GET['id']);
			if(empty($task['id'])){
				$this->ajaxReturn(array('title'=>'验证失败','message'=>'没有数据提交！'.$result,'status'=>'error'));
			}
			$model=new \Data\Model\DataModel();
			$id=$model->FailureDraft($task);
			if(!empty($id)){
				$callback=$this->GetCallback();
				$this->ajaxReturn(array('title'=>'稿件操作','message'=>'操作成功!','status'=>'ok','refresh'=>false,'callback'=>"GetListDraft('".$callback[0]."','".$callback[1]."')"));
			}else{
				$this->ajaxReturn(array('title'=>'稿件操作','message'=>$model->getError(),'status'=>'error'));
			}
		}
	}
	
	function GetCallback(){
		
		$type=intval($_POST['type']);
		$url='/post/task/listdraft/id/'.intval($_GET['id']).'/type/'.$type.'/oid/0/p/'.intval($_POST['pagenum']);
		if($type==1){ //未审核
			$javascript='#ListDraftNotreviewed';
		}elseif($type==2){ //中标
			$javascript='#ListDraftSuccess';
		}elseif($type==3){//失败
			$javascript='#ListDraftFailure';
		}else{
			$javascript='#ListDraft';
		}
		return array($url,$javascript);
	}
	
	//交接原件
	function deliveryAction(){
		if(intval($_GET['mobile'])){
			//移动
		}else{
			//模块
			
			$model=new \Data\Model\DataModel();
			$task=$model->GetData($_GET['id']);
			if(empty($task['id'])){
				$this->ajaxReturn(array('title'=>'验证失败','message'=>'没有数据提交！'.$result,'status'=>'error'));
			}
			
			$model=new \Data\Model\DataModel();
			$data=$model->DeliveryDraft($task);
			if(!empty($data)){
				$this->ajaxReturn(array('title'=>'稿件操作','message'=>'操作成功!','status'=>'ok','refresh'=>true,'data'=>$data));
			}else{
				$this->ajaxReturn(array('title'=>'稿件操作','message'=>$model->getError(),'status'=>'error'));
			}
		}
	}

	//退款
	function refundAction(){
		if(intval($_GET['mobile'])){
			//移动
		}else{
			//模块
			
			$model=new \Data\Model\DataModel();
			$task=$model->GetData($_GET['id']);
			if(empty($task['id'])){
				$this->ajaxReturn(array('title'=>'验证失败','message'=>'没有数据提交！'.$result,'status'=>'error'));
			}
			
			$model=new \Data\Model\DataModel();
			$data=$model->RefundOrder($task);
			if(!empty($data)){
				$this->ajaxReturn(array('title'=>'退款操作','message'=>'操作成功!','status'=>'ok','refresh'=>true,'data'=>$data));
			}else{
				$this->ajaxReturn(array('title'=>'退款操作','message'=>$model->getError(),'status'=>'error'));
			}
		}
	}
	
	//驳回
	function rejectAction(){
		if(intval($_GET['mobile'])){
			//移动
		}else{
			//模块
			
			$model=new \Data\Model\DataModel();
			$task=$model->GetData($_GET['id']);
			if(empty($task['id'])){
				$this->ajaxReturn(array('title'=>'验证失败','message'=>'没有数据提交！'.$result,'status'=>'error'));
			}
			$model=new \Data\Model\DataModel();
			$RejectData['content']=$_POST['RejectContent'];
			$RejectData['task_id']=$task['id'];
			$RejectData['time']=NowTime();
			$oid=intval($_POST['oid']);
			$draft= M('DataOrder')->token(false)->where(" oid=$oid ")->find();
			$RejectData['seller_uid']=$draft['seller_uid'];
			$RejectData['buyer_uid']=$draft['buyer_uid'];
			// 添加驳回信息
			M('reject')->add($RejectData);
			
			$data=$model->RejectOrder($task);
			if(!empty($data)){
				$this->ajaxReturn(array('title'=>'驳回操作','message'=>'操作成功!','status'=>'ok','refresh'=>true,'data'=>$data));
			}else{
				$this->ajaxReturn(array('title'=>'驳回操作','message'=>$model->getError(),'status'=>'error'));
			}
		}
	}	
	//支付订单
	function payorderAction(){
		if(intval($_GET['mobile'])){
			//移动
		}else{
			//模块
			
			$model=new \Data\Model\DataModel();
			$task=$model->GetData($_GET['id']);
			if(empty($task['id'])){
				$this->ajaxReturn(array('title'=>'验证失败','message'=>'没有数据提交！'.$result,'status'=>'error'));
			}
			
			$model=new \Data\Model\DataModel();
			$data=$model->PayOrder($task);
			if(!empty($data)){
				$this->ajaxReturn(array('title'=>'订单操作','message'=>'操作成功!','status'=>'ok','refresh'=>true,'data'=>$data));
			}else{
				$this->ajaxReturn(array('title'=>'订单操作','message'=>$model->getError(),'status'=>'error'));
			}
		}
	}
	
	//提交评价
	function evaluateAction(){
		if(intval($_GET['mobile'])){
			//移动
		}else{
			//模块
			
			$model=new \Data\Model\DataModel();
			$task=$model->GetData($_GET['id']);
			if(empty($task['id'])){
				$this->ajaxReturn(array('title'=>'验证失败','message'=>'没有数据提交！'.$result,'status'=>'error'));
			}
			
			$model=new \Data\Model\DataModel();
			$data=$model->Evaluate($task);
			if(!empty($data)){
				$this->ajaxReturn(array('title'=>'评价操作','message'=>'评价成功!','status'=>'ok','refresh'=>true,'data'=>$data));
			}else{
				$this->ajaxReturn(array('title'=>'评价操作','message'=>$model->getError(),'status'=>'error'));
			}
		}
	}
}